/* return all items by default */
#define DEFAULT_LIMIT -1
+/* limit the size of the list */
+#define MAX_LIST_SIZE 1000
+
/* keep in sync with xdgmime */
#define GTK_RECENT_DEFAULT_MIME "application/octet-stream"
const gchar *filename);
static void gtk_recent_manager_clamp_to_age (GtkRecentManager *manager,
gint age);
+static void gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
+ const gint size);
+
static void gtk_recent_manager_enabled_changed (GtkRecentManager *manager);
{
GtkSettings *settings;
gint age;
+ gint max_size = MAX_LIST_SIZE;
gboolean enabled;
settings = gtk_settings_get_default ();
enabled = TRUE;
}
- if (age == 0 || !enabled)
+ if (age == 0 || max_size == 0 || !enabled)
{
g_bookmark_file_free (priv->recent_items);
priv->recent_items = g_bookmark_file_new ();
priv->size = 0;
}
- else if (age > 0)
- gtk_recent_manager_clamp_to_age (manager, age);
+ else
+ {
+ if (age > 0)
+ gtk_recent_manager_clamp_to_age (manager, age);
+ if (max_size > 0)
+ gtk_recent_manager_clamp_to_size (manager, max_size);
+ }
}
if (priv->filename != NULL)
g_strfreev (uris);
}
+static void
+gtk_recent_manager_clamp_to_size (GtkRecentManager *manager,
+ const gint size)
+{
+ GtkRecentManagerPrivate *priv = manager->priv;
+ gchar **uris;
+ gsize n_uris, i;
+
+ if (G_UNLIKELY (!priv->recent_items) || G_UNLIKELY (size < 0))
+ return;
+
+ uris = g_bookmark_file_get_uris (priv->recent_items, &n_uris);
+
+ if (n_uris < size)
+ return;
+
+ for (i = 0; i < n_uris - size; i++)
+ {
+ const gchar *uri = uris[i];
+ g_bookmark_file_remove_item (priv->recent_items, uri, NULL);
+ }
+
+ g_strfreev (uris);
+}
+
/*****************
* GtkRecentInfo *
*****************/